import request from '@/utils/request'

const roleApi = {
  queryAuthedPermission: '/api/auth/permission/routes',
  queryAuthedAddRole: '/api/app/roles/', // 添加角色
  queryAuthedAllRole: '/api/app/roles/', // 获取全部角色
  queryAuthedEdit: '/api/app/role/'
}

class Service {
  /**
   * @description GET 保存授权菜单权限
   */
  static postAuthPermission(data: any) {
    return request({
      url: `/api/app/permiss?id=${data}`,
      method: 'GET',
      json: true,
      data
    }).then((res) => {
      if (res.code === 200) {
        return Promise.resolve(res)
      }
      return Promise.reject(res)
    })
  }

  /* 
    获取全部角色
  */

  static getAuthRoles() {
    return request({
      url: roleApi.queryAuthedAllRole,
      method: 'GET',
      json: true
    }).then((res) => {
      console.log(res)
      if (res.code === 200) {
        return Promise.resolve(res)
      }
      return Promise.reject(res)
    })
  }

  /*
    添加角色  
  */
  static postAuthAddRoles(data: any) {
    return request({
      url: roleApi.queryAuthedAddRole,
      method: 'POST',
      json: true,
      data
    }).then((res) => {
      if (res.code === 200) {
        return Promise.resolve(res)
      }
      return Promise.reject(res)
    })
  }

  /*
    删除角色
  */

  static deleteAuthedRoles(data: any) {
    return request({
      url: `/api/app/roles?id=${data}`,
      method: 'DELETE',
      json: true,
      data
    }).then((res) => {
      if (res.code === 200) {
        return Promise.resolve(res)
      }
      return Promise.reject(res)
    })
  }

  /*
      获取当前权限
    */
  static queryAuthedEdit(data: any) {
    return request({
      url: '/api/app/role/',
      method: 'PUT',
      json: true,
      data
    }).then((res) => {
      if (res.code === 200) {
        return Promise.resolve(res)
      }
      return Promise.reject(res)
    })
  }
}
export default Service
